package com.example.paper.http.factory;

import com.example.paper.http.retrofit.SignRetrofit;
import com.example.paper.http.retrofit.ToKenSingRetrofit;
import com.example.paper.http.retrofit.TokenRetrofit;
import com.example.paper.http.retrofit.UploadRetrofit;

public class HttpFactory {

    public HttpFactory() {
    }

    private static HttpFactory instance;

    public static HttpFactory getInstance() {
        if (instance == null) {
            instance = new HttpFactory();
        }
        return instance;
    }

    //相同类型才能用
    private HttpImpl upload, sign, tokenString, token;

    public HttpImpl factory(HttpType httpType) {
        HttpImpl http = null;
        //选择性创建
        switch (httpType) {
            case UPLOADTYPE:
                if (upload == null) {
                    upload = new UploadRetrofit.Build().build();
                }
                http = upload;
                break;
            case SIGNTYPE:
                if (sign == null) {
                    sign = new SignRetrofit.Build().build();
                }
                http = sign;
                break;
            case TOKENSIGNTYPE:
                if (tokenString == null) {
                    tokenString = new ToKenSingRetrofit.Build().Build();
                }
                http = tokenString;
                break;
            case TOKEN:
                if (token == null) {
                    token = new TokenRetrofit.Build().build();
                }
                http = token;
                break;
        }
        return http;
    }

}
